/**
 * 
 */
package edu.umd.clip.lm.playground;

import org.w3c.dom.Document;
import org.w3c.dom.Element;

import edu.umd.clip.lm.util.XMLizable;
import edu.umd.clip.lm.util.tree.*;
/**
 * @author Denis Filimonov <den@cs.umd.edu>
 *
 */
public class TestTreeIterators {

	private static class Int extends XMLizable {
		int i;
		
		public Int(int i) {
			this.i = i;
		}
		/* (non-Javadoc)
		 * @see edu.umd.clip.lm.util.XMLizable#createXML(org.w3c.dom.Document)
		 */
		@Override
		public Element createXML(Document doc) {
			// TODO Auto-generated method stub
			return null;
		}

		/* (non-Javadoc)
		 * @see edu.umd.clip.lm.util.XMLizable#getElementName()
		 */
		@Override
		public String getElementName() {
			// TODO Auto-generated method stub
			return null;
		}
		@Override
		public String toString() {
			return Integer.toString(i);
		}
	}
	
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		int count = 0;
		BinaryTree<Int> tree = new BinaryTree<Int>(new Int(count++));
		BinaryTree<Int> left = new BinaryTree<Int>(new Int(count++));
		tree.attachLeft(left);
		BinaryTree<Int> right = new BinaryTree<Int>(new Int(count++));
		tree.attachRight(right);
		
		left.attachLeft(new BinaryTree<Int>(new Int(count++)));
		left.attachRight(new BinaryTree<Int>(new Int(count++)));
		
		right.attachLeft(new BinaryTree<Int>(new Int(count++)));
		right.attachRight(new BinaryTree<Int>(new Int(count++)));
		
		BinaryTreeIterator<Int> iterator;
		
		System.out.print("Preorder:");
		iterator = tree.getPreOrderIterator();
		while(iterator.hasNext()) {
			Int i = iterator.next();
			System.out.print(" " + i.toString());
		}
		System.out.println();
		
		System.out.print("Postorder:");
		iterator = tree.getPostOrderIterator();
		while(iterator.hasNext()) {
			System.out.print(" " + iterator.next().toString());
		}
		System.out.println();
		
		System.out.print("Leaves:");
		iterator = tree.getLeafIterator();
		while(iterator.hasNext()) {
			System.out.print(" " + iterator.next().toString());
		}
		System.out.println();
		
	}

}
